import 'package:ctrip_flutter/app/main_page.dart';
import 'package:ctrip_flutter/dart/dart_type.dart';
import 'package:ctrip_flutter/dart/opp_learn.dart';
import 'package:ctrip_flutter/flutter_demo/Hero_learn2.dart';
import 'package:ctrip_flutter/flutter_demo/animation_learn.dart';
import 'package:ctrip_flutter/flutter_demo/animation_learn2.dart';
import 'package:ctrip_flutter/flutter_demo/animation_learn3.dart';
import 'package:ctrip_flutter/flutter_demo/futureBuilder_learn.dart';
import 'package:ctrip_flutter/flutter_demo/grid_learn.dart';
import 'package:ctrip_flutter/flutter_demo/hero_learn.dart';
import 'package:ctrip_flutter/flutter_demo/http_learn.dart';
import 'package:ctrip_flutter/flutter_demo/image_learn.dart';
import 'package:ctrip_flutter/flutter_demo/list_learn.dart';
import 'package:ctrip_flutter/flutter_demo/photo_app_page.dart';
import 'package:ctrip_flutter/flutter_demo/refresh_learn.dart';
import 'package:ctrip_flutter/flutter_demo/shared_learn.dart';
import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: Scaffold(
        appBar: AppBar(
          title: Text("Flutter 练习"),
        ),
        body: MyHomePage(),
      ),
      routes: <String, WidgetBuilder>{
        "photoApp": (context) => PhotoAppPage(),
        "image": (context) => ImageLearn(),
        "animation": (context) => AnimationLearn(),
        "animation2": (context) => AnimationLearn2(),
        "animation3": (context) => AnimatedBuilderPage(),
        "hero": (context) => HeroStart(),
        "hero2": (context) => HeroStart2(),
        "http": (context) => HttpLearn(),
        'FutureBuilderLearn': (context) => FutureBuilderLearn(),
        "SharedLearn": (context) => SharedLearn(),
        "main_app": (context) => MainPage(),
        "listview": (context) => ListViewPage(),
        "gridview": (context) => GridViewPage(),
        "refresh": (context) => RefreshPage(),

      },
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  bool byName = false;

  @override
  Widget build(BuildContext context) {
//     dartType.numType();  //数字类型
//    dartType.stringType();   //字符串
//    dartType.boolType(); //bool
//    dartType.listType();//list集合
//    dartType.mapType(); //Map
//    _oopLearn(); //面向对象
    return Container(
      child: SingleChildScrollView(
        child:  Column(
          children: <Widget>[
            SwitchListTile(
                title: Text('${byName ? "" : "不"}通过路由名跳转'),
                value: byName,
                onChanged: (value) {
                  setState(() {
                    byName = value;
                  });
                }),
            _item("调用相机", PhotoAppPage(), "photoApp"),
            _item("学习image", ImageLearn(), "photoApp"),
            _item("学习动画效果", AnimationLearn(), "animation"),
            _item("学习动画效果2", AnimationLearn2(), "animation2"),
            _item("AnimatedBuilder实现", AnimatedBuilderPage(), "animation3"),
            _item("Hero实现", HeroStart(), "hero"),
            _item("高级Hero实现", HeroStart2(), "hero2"),
            _item("Http学习", HttpLearn(), "http"),
            _item('FutureBuilder学习', FutureBuilderLearn(), 'FutureBuilderLearn'),
            _item("APP", MainPage(), "main_app"),
            _item("SharedLearn", SharedLearn(), "SharedLearn"),
            _item("ListView学习", ListViewPage(), "listview"),
            _item("GridView学习", GridViewPage(), "gridview"),
            _item("上啦加载下啦刷新学习", RefreshPage(), "refresh"),


          ],
        ),
      ),
    );
  }

  //面向对象
  void _oopLearn() {
    Logger log1 = Logger();
    Logger log2 = Logger();
    print(log1 == log2);

    Student.doPrint("打印一次啊");

    Student stu1 = Student("aje", "name", 12);
    Student.doPrint(stu1.school);

    Student stu2 = Student("beida", "Tom", 123);

    StudyFlutter studyFlutter = StudyFlutter();
    studyFlutter.study();
  }

  _item(String title, page, String routeName) {
    return Container(
      child: RaisedButton(
        onPressed: () {
          if (byName) {
            Navigator.pushNamed(context, routeName);
          } else {
            Navigator.push(
                context, MaterialPageRoute(builder: (context) => page));
          }
        },
        child: Text(title),
      ),
    );
  }
}
